package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.service.game.GameService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/game")
public class GameController {
    @Autowired
    private GameService gameService;

    @GetMapping("/cfg")
    public BaseRsp listGameCfg(){
        return gameService.listGameCfg();
    }

    @GetMapping("/account")
    public BaseRsp listUserGameAccount(@RequestParam(value = "uid", required = false) Long uid,
                                       @RequestParam(value = "game_id", required = false) String gameId,
                                       @RequestParam(value = "zone_id", required = false) String zoneId,
                                       @RequestParam(value = "game_account_id", required = false) String gameAccountId,
                                       @RequestParam(value = "from_bind_time", required = false) String fromBindTime,
                                       @RequestParam(value = "to_bind_time", required = false) String toBindTime,
                                       @RequestParam("offset") Integer offset,
                                       @RequestParam("limit") Integer limit){
        Map<String, Object> reqMap = new HashMap<>();
        if (uid != null){
            reqMap.put("uid", uid);
        }
        if (gameId != null){
            reqMap.put("game_id", gameId);
        }
        if (zoneId != null){
            reqMap.put("zone_id", zoneId);
        }
        if (gameAccountId != null){
            reqMap.put("game_account_id", gameAccountId);
        }
        if (!StringUtils.isEmpty(fromBindTime)){
            reqMap.put("from_bind_time", fromBindTime);
        }
        if (!StringUtils.isEmpty(toBindTime)){
            reqMap.put("to_bind_time", toBindTime);
        }
        if (offset != null){
            reqMap.put("offset", offset);
        }
        if (limit != null){
            reqMap.put("limit", limit);
        }
        return gameService.listUserGameAccount(reqMap);
    }
}
